﻿/**
 * 字体插件
 */
(function(E){

var fontNameList= [
		{name:'宋体', value:'SimSun'},
		{name:'仿宋体', value:'FangSong_GB2312'},
		{name:'微软雅黑', value:'Microsoft YaHei'},
		{name:'黑体', value:'SimHei'},
		{name:'楷体', value:'KaiTi_GB2312'},
		'Courier New',
		'Times New Roman',
		'Impact',
		'Georgia',
		'Arial',
		'Verdana',
		'Tahoma'
	];

E.plugin("FontName", {
	// _float:left;_width:100%; 用来修正IE6下鼠标mouseover事件
	// 否则只有鼠标处于文字上面时才会触发mouseover，当加上 _float:left;_width:100%; 后鼠标处于空白区域也可以触发mouseover事件了
	style: '.jqe-plugin-fontname a{text-decoration:none;color:#333333;display:block;padding:2px 30px;border:1px solid #eeeeee;background-color:#eeeeee;_float:left;_width:120px;padding-left:25px;}'
		+'.jqe-plugin-fontname a:hover{background-color:#ecf1f7;border:1px solid #aecff7;}'
		+'#panel_FontName .jqe-panel-body{padding:2px;}',
	
	isNeedTitle:0,
	// 插件图标设置
	icon: {
		width: 40,
		text: '字 体'
	},
	config: {
		// 面板宽度
		width: 180,
		
		HEIGHT: 340
	},
	
	selectedFont: {},
	
	init: function( self ){
		var html = [], typeofitem, list = fontNameList, font, name;
		
		for(var i=0, len = list.length; i<len; i++){
			typeofitem = typeof list[i];
			if(typeofitem === "string"){
				font=list[i];
				name=list[i];
			}else if (typeofitem === "object"){
				font=list[i].value;
				name=list[i].name;
			}
			
			html.push('<a href="jqe:FontName('+name+')" style="font-family: '+font+';line-height:22px" font="'+font+'">'+name+'</a>');
		}
		
		self.cache['html'] = '<div class="jqe-plugin-fontname">'+html.join('')+'</div>';
	},
	
	/**
	 * 设置字体
	 */
	set: function( Panel, self ){
		var font = self.selectedFont[E.eid] || 'SimSun';
		
		self.setFontName( font );
		self.hide();
		return 1;
	},
	
	
	menu: function( Panel, self ){
		// 设置面板
		Panel.set( self );
		return 1;
	},
	
	/**
	 * 
	 */
	action: function( target, panel, self ){
		var eid = E.eid, name = self.name, 
			font = target.closest('[font]').attr('font'),
			fontName = target.closest('[font]').text();
		if( font ){
			self.selectedFont[eid] = font;
			self.setFontName( font );
			self.hide();
			
			$('#'+eid+'-'+name).find('span.jqe-icon').text( fontName ).css('font-family', font);
		}
		return false;
	},
	
	//设置字体
	setFontName: function( value ){
		var self = this, name = self.name;
		E.execCommand(name, false, value);
	}
});

})(jQEditor);